package com.example.task1.ui.AllService.parking;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.ParkingHomeListBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class ParkingHomeListAdapter extends BaseAdapter<ParkingHomeListBean.RowsDTO> {

    private List<ParkingHomeListBean.RowsDTO> mData = new ArrayList<>();
    private Context context;
    private ImageView image;
    private TextView tvAddress;
    private TextView tvRates;
    private TextView tvPriceCaps;
    private TextView tvVacancy;
    private TextView tvDistance;
    private TextView tvName;

    public ParkingHomeListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<ParkingHomeListBean.RowsDTO> rows) {
        int size = mData.size();
        mData.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.parkinghomelist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<ParkingHomeListBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, ParkingHomeListBean.RowsDTO date) {
        MyApplication.glide(image, date.getImgUrl());
        tvAddress.setText("地址：" + date.getAddress());
        tvRates.setText("收费：" + date.getRates());
        tvPriceCaps.setText("封顶价格：" + date.getPriceCaps());
        tvVacancy.setText("空位个数：" + date.getVacancy());
        tvDistance.setText("距离：" + date.getDistance());
        tvName.setText(date.getParkName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context,ParkingHomeDetailsActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View view) {
        image = view.findViewById(R.id.image);
        tvAddress = view.findViewById(R.id.tv_address);
        tvRates = view.findViewById(R.id.tv_rates);
        tvPriceCaps = view.findViewById(R.id.tv_priceCaps);
        tvVacancy = view.findViewById(R.id.tv_vacancy);
        tvDistance = view.findViewById(R.id.tv_distance);
        tvName = view.findViewById(R.id.tv_name);
    }
}
